import 'dart:convert';
import 'dart:io';

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_my_web/pages/editarticle/EditarticlePage.dart';
import 'package:flutter_my_web/pages/home/HomePage.dart';
import 'package:flutter_lib/utils/LogUtils.dart';
import 'package:flutter_lib/utils/ShowDialogUtils.dart';
import 'package:flutter_my_web/pages/tools/sketch/SketchPage.dart';
import 'package:flutter_my_web/utils/lang/translation_service.dart';
import 'package:flutter_my_web/widget/TextWidget.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';
import 'package:get/get_navigation/src/routes/transitions_type.dart';
import 'package:responsive_framework/responsive_framework.dart';
import 'package:flutter_lib/utils/DpUtils.dart';
import 'package:worker_manager/worker_manager.dart';

import 'pages/tools/ToolsMainPage.dart';
void main() async{

  WidgetsFlutterBinding.ensureInitialized();
  // 滚动性能优化
  // 根据所涉及的频率差异, 启用此标志可以使滚动时的颤动减少多达97%
  GestureBinding.instance.resamplingEnabled = true;

  SystemChrome.setPreferredOrientations([
    DeviceOrientation.landscapeLeft,
    DeviceOrientation.landscapeRight
  ]);
  runApp(GetMaterialApp(
    // debugShowCheckedModeBanner: false,
    enableLog: true,
    defaultTransition: Transition.fade,
    opaqueRoute: Get.isOpaqueRouteDefault,
    popGesture: Get.isPopGestureEnable,
    locale: TranslationService.locale,
    // locale: Get.deviceLocale,//使用默认的语言环境
    fallbackLocale: TranslationService.fallbackLocale,

    //指定出错时候，默认的语言环境
    translations: TranslationService(),
    home: MyApp(),
  ));
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    DpUtils.dputils_isUseScreenUatils = false;
    SpUtils.sputils_isUseScreenUatils = false;
    ScreenUtil.init(
      context,
      // Orientation.portrait,
      designSize: Size(378, 815),
    );
    return MaterialApp(
      title: 'FlutterBlog',
      theme: ThemeData(
        fontFamily: "Avenir",
        primarySwatch: Colors.blue,
      ),
      home: ToolsMainPage(),
    );
  }
}



class MainPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      //浮动按钮
      floatingActionButton: FloatingActionButton(
        //浮动按钮图标
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Icon(
              Icons.library_add_outlined,
              color: Colors.white,
            ),
            SimpleText("添加文章",color: Colors.white,fontSize: 8.sp,)
          ],
        ),
        //浮动按钮背景色
        onPressed: () async {
          Get.to(EditarticlePage());
          // BaiDuYunUtils.saveMD("", "test.md", 0, 3, "11111111");
          // AliyunOSS().postObject("1.md",Uint8List.fromList(utf8.encode("12你好哈哈哈哈3123")));
        },
      ),
      //浮动按钮的位置
      floatingActionButtonLocation:
      FloatingActionButtonLocation.endFloat,
      body: SafeArea(child: HomePage()),
    );
  }
}

